package com.zx.ishopping.mapper;

import com.github.pagehelper.Page;
import com.zx.ishopping.DTO.ProductPageDTO;

import com.zx.ishopping.annotation.AutoFill;
import com.zx.ishopping.entity.Products;
import com.zx.ishopping.enums.OperationEnum;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductMapper {


    /**
     * 根据分类id查询商品
     * @param categoryId
     * @retur
     */
    @Select("select count(*) from products where category_id = #{categoryId}")
    Long getProductNumByCategoryId(Long categoryId);

    /**
     * 分页查询商品
     * @param productPageDTO
     * @return
     */
    Page<Products> pageQuery(ProductPageDTO productPageDTO);

    /**
     * 更新分类数据
     * @param products
     */
    @AutoFill(OperationEnum.UPDATE)
    int update(Products products);

    /**
     * 根据id删除商品
     * @param ids
     */
    void deleteProduct(List<Long> ids);

    /**
     * 添加商品
     * @param products
     */
    @AutoFill(OperationEnum.INSERT)
    @Insert("insert into products(name,description,image_url,stock,status,price,version ,category_id,create_time,update_time,create_user) values(#{name},#{description},#{imageUrl},#{stock},#{status},#{price},#{version},#{categoryId},#{createTime},#{updateTime},#{createUser})")
    void addProduct(Products products);

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @Select("select * from products where id = #{id}")
    Products getById(Long id);

  
    /**
     * 查询最畅销商品
     * @return
     */
    List<Products> getBestSaleProductList();

    /**
     * 深分页查询
     * @param productPageDTO
     * @return
     */
    List<Products> cursorQuery(ProductPageDTO productPageDTO);
}
